//
// SoapTrace.Net - A soap message monitoring utility. 
//
// Copyright (C) 2005 Matthew Ward
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Matthew Ward (mrward@users.sourceforge.net)

using NUnit.Framework;
using SoapTrace.Core.Communication;
using System;
using System.Text;

namespace SoapTrace.Tests
{
	/// <summary>
	/// Tests the <see cref="SoapHeader.IsHttpStartLine"/> method.
	/// </summary>
	[ TestFixture ]
	public class SoapHttpHeaderTestFixture
	{
		/// <summary>
		/// Check a valid HTTP line.
		/// </summary>
		[ Test ]
		public void ValidStartLine1( )
		{
			byte[ ] Bytes = GetBytes( "POST /abc.asmx HTTP/1.1\r\n" );
			Assert.IsTrue( SoapHeader.IsHttpStartLine( Bytes ), "Should be a valid http header." );
		}
		
		/// <summary>
		/// Check a valid HTTP line.
		/// </summary>
		[ Test ]
		public void ValidStartLine2( )
		{
			byte[ ] Bytes = GetBytes( "POST /foo.asmx HTTP/1.0\r\n" );
			Assert.IsTrue( SoapHeader.IsHttpStartLine( Bytes ), "Should be a valid http header." );
		}		
		
		/// <summary>
		/// Check a invalid HTTP line.
		/// </summary>
		[ Test ]
		public void InvalidStartLine1( )
		{
			byte[ ] Bytes = GetBytes( "HTTP/1.0\r\n" );
			Assert.IsFalse( SoapHeader.IsHttpStartLine( Bytes ), "Should not be a valid http header." );
		}	
		
		/// <summary>
		/// Check a invalid HTTP line.
		/// </summary>
		[ Test ]
		public void InvalidStartLine2( )
		{
			byte[ ] Bytes = GetBytes( "a HTTP/1.0\r\n" );
			Assert.IsFalse( SoapHeader.IsHttpStartLine( Bytes ), "Should not be a valid http header." );
		}	
		
		/// <summary>
		/// Check a invalid HTTP line.
		/// </summary>
		[ Test ]
		public void InvalidStartLine3( )
		{
			byte[ ] Bytes = GetBytes( "GET /a.asmx HTTP//.0\r\n" );
			Assert.IsFalse( SoapHeader.IsHttpStartLine( Bytes ), "Should not be a valid http header." );
		}		
		
		/// <summary>
		/// Check a invalid HTTP line.
		/// </summary>
		[ Test ]
		public void InvalidStartLine4( )
		{
			byte[ ] Bytes = GetBytes( "GET b c d e HTTP/1.0\r\n" );
			Assert.IsFalse( SoapHeader.IsHttpStartLine( Bytes ), "Should not be a valid http header." );
		}			
		
		/// <summary>
		/// Check an empty string.
		/// </summary>
		[ Test ]
		public void EmptyString( )
		{
			byte[ ] Bytes = GetBytes( String.Empty );
			Assert.IsFalse( SoapHeader.IsHttpStartLine( Bytes ), "Should not be a http header." );			
		}
		
		/// <summary>
		/// Check an xml string.
		/// </summary>
		[ Test ]
		public void XmlString( )
		{
			byte[ ] Bytes = GetBytes( "<xml></xml>" );
			Assert.IsFalse( SoapHeader.IsHttpStartLine( Bytes ), "Should not be a http header." );						
		}
		
		private byte[ ] GetBytes( string text )
		{
			return UnicodeEncoding.UTF8.GetBytes( text );
		}
	}
}
